﻿using Pay.DTO;
using Pay.DTO.Token;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pay.Service {
    public class TokenCardService : ServiceBase, ITokenCardService, IDisposable {
        private IUnitOfWork _iUnitOfWork;
        private IMerchantService _iMerchantService;
        private ISettingService _iSettingService;

        public TokenCardService(IUnitOfWork iUnitOfWork, IMerchantService iMerchantService, ISettingService iSettingService) : base(iUnitOfWork) {
            _iUnitOfWork = iUnitOfWork;
            _iMerchantService = iMerchantService;
            _iSettingService = iSettingService;
        }

        /// <summary>
        /// 银行列表
        /// </summary>
        /// <returns>The machine.</returns>
        public async Task<List<bank_resp>> GetBank() {
            var data = new bank_resp { };
            var apiResult = await ChannelApi.Current.PostApi<result_data_base<List<bank_resp>>>(data);
            if (apiResult.result_code == 1000) {
                return apiResult.data;
            }
            return new List<bank_resp>();
        }

        /// <summary>
        /// 银行卡主题列表
        /// </summary>
        /// <returns>The bank.</returns>
        public async Task<List<banktopic_resp>> GetBankTopic() {
            var data = new banktopic_resp { };
            var apiResult = await ChannelApi.Current.PostApi<result_data_base<List<banktopic_resp>>>(data);
            if (apiResult.result_code == 1000) {
                return apiResult.data;
            }
            return new List<banktopic_resp>();
        }


        /// <summary>
        /// 银行卡标签列表
        /// </summary>
        /// <returns>The bank.</returns>
        public async Task<List<banktag_resp>> GetBankTag() {
            var data = new banktag_resp { };
            var apiResult = await ChannelApi.Current.PostApi<result_data_base<List<banktag_resp>>>(data);
            if (apiResult.result_code == 1000) {
                return apiResult.data;
            }
            return new List<banktag_resp>();
        }

        /// <summary>
        /// 银行卡通道列表
        /// </summary>
        /// <returns>The bank topic.</returns>
        public async Task<PagedResult<bank_card_resp>> GetBankCard(card_req model) {
            var apiResult = await ChannelApi.Current.PostApi<t_ApiPagedResult<bank_card_resp>>(model);
            if (apiResult.result_code == 1000) {
                return new PagedResult<bank_card_resp> { page = apiResult.page, size = apiResult.size, rows = apiResult.rows };
            }
            return new PagedResult<bank_card_resp>();
        }

        /// <summary>
        /// 银行卡通道列表
        /// </summary>
        /// <returns>The bank card detail.</returns>
        /// <param name="id">卡种通道id.</param>
        public async Task<bank_carddetail_resp> GetBankCardDetail(long id) {
            var data = new t_query_frist_model { method = "11004", id = id };
            var apiResult = await ChannelApi.Current.PostApi<result_data_base<bank_carddetail_resp>>(data);
            if (apiResult.result_code == 1000) {
                return apiResult.data.ToDtoObject<bank_carddetail_resp>();
            }
            return null;
        }

        /// <summary>
        /// 保存申卡记录
        /// </summary>
        /// <returns>The bank card detail.</returns>
        /// <param name="model">Model.</param>
        public async Task<card_save_resp> Post(DTO.Token.card_save_model model) {
            var apiResult = await ChannelApi.Current.PostApi<result_data_base<card_save_resp>>(model);
            if (apiResult.result_code == 1000) {
                return apiResult.data.ToDtoObject<card_save_resp>();
            }
            return null;
        }
    }
}
